/*
 * Copyright 2002-2015 the Unicorn Team http://www.unicorn.pw/
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.unicorn.auth.web.extension.util;

import javax.servlet.http.HttpServletRequest;

/**
 * 本地化WEB工具</br>
 * 
 * @author xunaidong
 * @since 1.0.0 Feb 3, 2015
 */
public class NativeWebUtil {

	private NativeWebUtil() {

	}
	/**
	 * 
	 * 获取客户端真实IP<br/> 
	 * @author xunaidong 
	 * @param request
	 * @return 
	 * @since 1.0.0
	 */
	public static String getClientIP(HttpServletRequest request) {

		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		return ip.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : ip;

	}
	
	
}
